﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Sunimage.Spjg.BLL.SysMgr;
using Sunimage.Spjg.Common.SysMgr;
using Sunimage.Spjg.Web.Helper;
using Sunimage.Spjg.Common;
using Sunimage.Spjg.BLL.Helper;

namespace Sunimage.Spjg.Web
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //#if DEBUG

            //this.UserName.Text = "admin";
            //this.PassWord.Text = SystemConfiguration.GetDefaultGsjUserPassword();
            //this.PassWord.TextMode = TextBoxMode.SingleLine;

            //#endif
        }

        protected void BtnLoginGsj_Click(object sender, EventArgs e)
        {
            // throw new Exception("测试ajax异常");
            if (GsjUserHelper.Login(this.UserName.Text.Trim(), this.PassWord.Text))
            {
                UserBl userBl = new UserBl();
                User user = userBl.GetByUsername(this.UserName.Text.Trim());
                if (user.Role == RoleType.Administrator)//到管理界面
                    Response.Redirect("~/admin/index.aspx");
                else
                    Response.Redirect("~/UserClient/index.aspx");

                //if (HttpContext.Current.Session["gsjUserlastUrl"] != null)
                //{
                //    string url = HttpContext.Current.Session["gsjUserlastUrl"].ToString();
                //    HttpContext.Current.Session["gsjUserlastUrl"] = null;
                //    Response.Redirect(url, true);
                //}

                //else
                //    Response.Redirect("index.aspx", true);
            }
            else
            {
                ltrGsjMsg.Text = "用户名或密码错误！";
            }
        }
    }
}